{extend name="Public:base"/}

{block name="main"}
<div class="box-info">
    <form id="myform" name="myform" action="{:U('Category/add')}" method="post">

        <ul class="nav nav-tabs" role="tablist">
            <li class="nav-item">
                <a class="nav-link active" data-toggle="tab" href="#tab1">基本设置</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#tab2">SEO设置</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#tab3">扩展字段</a>
            </li>
        </ul>
        <div class="tab-content mt-2">
            <div class="tab-pane fade show active" id="tab1">
                <div class="form-group row">
                    <label class="col-md-2 text-right">上级栏目</label>
                    <div class="col-md-5">
                        <select name="parentid" class="form-control">
                            <option value="">作为一级栏目</option>
                            {$select_categorys}
                        </select>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">内容模型</label>
                    <div class="col-md-5">
                        {:Form::select(
                        array('field'=>'modelid',
                        'options'=>$model,
                        'options_key'=>'id,name',
                        'setup'=>array('onchange'=>'changetemplate(this.value)')),
                        $parentCatData['modelid']
                        )}
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">栏目名称</label>
                    <div class="col-md-5">
                        <input type="text" name="catname" id="catname" class="form-control" value=""  minlength="1" />
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">英文栏目名称</label>
                    <div class="col-md-5">
                        <input type="text" name="wap_catname" id="wap_catname" class="form-control" value=""  minlength="1" />
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">继承</label>
                    <div class="col-md-5">
                        <input type="radio" name="inherit"  value="1">开启
                        <input type="radio" name="inherit" checked value="0">关闭
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">栏目图片</label>
                    <div class="col-md-5">
                        <div class="thumb_image">
                            <div id="image_aid_box"></div>
                            <a class="thumbnail" href="javascript:swfupload('image','{:get_auth(1,'1048576',1)}',yesdo);">
                                <img height="80" src="__IMG__/upload_thumb.png" id="image_pic" >
                            </a>
                            <input type="button" value="取消图片" onclick="javascript:clean_thumb('image');" class="btn btn-sm btn-primary"/>
                            <input type="hidden" id="image" name="image" value="{$parentCatData['image']}"/>
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">多栏目设置: </label>
                    <div class="col-md-5">
                        <input type="checkbox" id="chage_all" lay-skin="primary" name="chage_all" value="1"/>将以下设置应用到所有子栏目
                    </div>
                </div>
                <div class="form-group row" >
                    <label class="col-md-2 text-right">pc导航</label>
                    <div class="col-md-5">
                    {:Form::radio(array('field'=>'ismenu','options'=>array('1'=>'是','0'=>'否')),1)}
                    </div>
                </div>
                <div class="form-group row" >
                    <label class="col-md-2 text-right">wap导航</label>
                    <div class="col-md-5">
                    {:Form::radio(array('field'=>'is_wap_menu','options'=>array('1'=>'是','0'=>'否')),1)}
                    </div>
                </div>
                <div class="form-group row" >
                    <label class="col-md-2 text-right">新窗口打开</label>
                    <div class="col-md-5">
                    {:Form::radio(array('field'=>'isblank','options'=>array('1'=>'是','0'=>'否')),0)}
                    </div>
                </div>
                <div class="form-group row" id="pagesize_section">
                    <label class="col-md-2 text-right">分页条数</label>
                    <div class="col-md-5">
                    <input type="text" name="pagesize" class="form-control w-100px" value="{if condition="!empty($vo['pagesize'])"}{$vo['pagesize']}{/if}"/>
                    <font color="red">为空时默认值为系统设置的值</font>
                    </div>
                </div>
                <div class="form-group row" id="template_list_section">
                    <label class="col-md-2 text-right">列表页模板</label>
                    <div class="col-md-5">
                    <input  name="template_list" class="form-control w-300px">
                    <input lay-ignore type="checkbox" class="input_checkbox pull-left" id="listtype" name="listtype" onclick="javascript:templatetype();" value="1" {if condition="!empty($vo['listtype'])"}checked{/if} />是否为封面栏目
                    </div>
                </div>
                <div class="form-group row" id="template_show_section">
                    <label class="col-md-2 text-right">内容页模板</label>
                    <div class="col-md-5">
                        <input name="template_show" class="form-control w-300px">
                    </div>
                </div>
            </div>

            <div class="tab-pane fade" id="tab2">
                <div class="form-group row">
                    <label class="col-md-2 text-right">栏目标题</label>
                    <div class="col-md-5">
                        <input name='title' type='text'  value="" class="form-control"  size='60' maxlength='150'>
                        <label>针对搜索引擎设置的标题</label>
                    </div>
                </div>

                <div class="form-group row">
                    <label class="col-md-2 text-right">栏目关键词</label>
                    <div class="col-md-5">
                        <input name="keywords" type="text" class="form-control" >
                        <label>关键字中间用半角逗号隔开</label>
                    </div>
                </div>

                <div class="form-group row">
                    <label class="col-md-2 text-right">栏目描述</label>
                    <div class="col-md-5">
                        <textarea name="description" class="form-control" rows="5" cols="60"></textarea>
                        <label>针对搜索引擎设置的网页描述</label>
                    </div>
                </div>
            </div>

            <div class="tab-pane fade" id="tab3">
                <div class="row">
                    <div class="col-6">
                        <div class="card">
                            <div class="card-body extend_list"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group row">
            <div class="col-md-5 offset-2">
                <button type="submit" class="btn btn-primary">提交</button>
                <button type="button" class="btn btn-danger" onclick="javascript:history.back(-1);return false;">返回</button>
            </div>
        </div>
    </form>
</div>


{/block}

{block name="script"}

<script type="text/javascript">
    //扩展字段处理
    function extend_type(type){
        if(type == 'radio' || type == 'checkbox'){
            $('.setting_radio').show();
            $('.setting_radio textarea').attr('disabled',false);
        }else{
            $('.setting_radio').hide();
            $('.setting_radio textarea').attr('disabled',true);
        }
    }
    $(function(){
        //添加扩展字段
        $('.add_extend a').click(function(){
            var fieldname = $('input[name="extend_add[fieldname]"]').val();
            var type = $('select[name="extend_add[type]"]').val();
            var setting = {};
            setting.title = $('input[name="extend_add[setting][title]"]').val();
            setting.tips = $('input[name="extend_add[setting][tips]"]').val();
            setting.style = $('input[name="extend_add[setting][style]"]').val();
            setting.option = $('textarea[name="extend_add[setting][option]"]').val();

            if(fieldname == ''){
                alert("键名不能为空！");
                return false;
            }else{
                if(fieldname.replace(/^[0-9a-zA-Z_]{1,}$/g) != 'undefined'){
                    alert("键名只允许数字，字母，下划线！");
                    return false;
                }
            }
            if(type == ''){
                alert("类型不能为空！");
                return false;
            }
            if(setting.title == ''){
                alert("名称不能为空！");
                return false;
            }

            //单选框
            if(type == 'input'){
                $('.extend_list').append('<div class="form-group">' +
                    '<label>'+setting.title+'(<a href="javascript:;;" class="extend_del">删除</a>)</label><div class="y-bg"> <input type="text" class="input" style="'+setting.style+'"  name="extend['+fieldname+']" value="" placeholder="'+setting.tips+'"> <input type="hidden" name="extend_config['+fieldname+'][fieldname]" value="'+fieldname+'"/> <input type="hidden" name="extend_config['+fieldname+'][type]" value="'+type+'"/> <input type="hidden" name="extend_config['+fieldname+'][setting][title]" value="'+setting.title+'"/> <input type="hidden" name="extend_config['+fieldname+'][setting][tips]" value="'+setting.tips+'"/>\<input type="hidden" name="extend_config['+fieldname+'][setting][style]" value="'+setting.style+'"/> <textarea name="extend_config['+fieldname+'][setting][option]" style="display:none;">'+setting.option+'</textarea> </div> </div>');
            }else if(type == 'textarea'){
                //多行文本框
                $('.extend_list').append('<div class="form-group"> ' +
                    '<label>'+setting.title+'(<a href="javascript:;;" class="extend_del">删除</a>)</label> <div class="y-bg"> <textarea name="extend['+fieldname+']" style="'+setting.style+'" placeholder="'+setting.tips+'"></textarea> <input type="hidden" name="extend_config['+fieldname+'][fieldname]" value="'+fieldname+'"/> <input type="hidden" name="extend_config['+fieldname+'][type]" value="'+type+'"/> <input type="hidden" name="extend_config['+fieldname+'][setting][title]" value="'+setting.title+'"/> <input type="hidden" name="extend_config['+fieldname+'][setting][tips]" value="'+setting.tips+'"/> <input type="hidden" name="extend_config['+fieldname+'][setting][style]" value="'+setting.style+'"/> <textarea name="extend_config['+fieldname+'][setting][option]" style="display:none;">'+setting.option+'</textarea> </div> </div>');
            }else if(type == 'password'){
                //密码框
                $('.extend_list').append('<div class="form-group"> <label>'+setting.title+'(<a href="javascript:;;" class="extend_del">删除</a>)</label> <div class="y-bg"> <input type="password" class="input" style="'+setting.style+'"  name="extend['+fieldname+']" value="" placeholder="'+setting.tips+'"> <input type="hidden" name="extend_config['+fieldname+'][fieldname]" value="'+fieldname+'"/> <input type="hidden" name="extend_config['+fieldname+'][type]" value="'+type+'"/> <input type="hidden" name="extend_config['+fieldname+'][setting][title]" value="'+setting.title+'"/> <input type="hidden" name="extend_config['+fieldname+'][setting][tips]" value="'+setting.tips+'"/> <input type="hidden" name="extend_config['+fieldname+'][setting][style]" value="'+setting.style+'"/> <textarea name="extend_config['+fieldname+'][setting][option]" style="display:none;">'+setting.option+'</textarea> </div> </div>');
            }else if(type == 'radio'){
                //单选框
                if(setting.option == ''){
                    alert('选项不能为空！');
                    return false;
                }
                var html = '';
                var op = setting.option.split("\n");
                $.each(op,function(i,rs){
                    var at = rs.split("|");
                    html += '<label><input name="extend['+fieldname+']" value="'+at[1]+'" type="radio" > '+at[0]+'</label>';
                });
                var tpl = '<div class="form-group"> ' +
                    '<label>'+setting.title+'(<a href="javascript:;;" class="extend_del">删除</a>)</label> ' +
                    '<div class="y-bg">'+html+
                    '<input type="hidden" name="extend_config['+fieldname+'][fieldname]" value="'+fieldname+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][type]" value="'+type+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][title]" value="'+setting.title+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][tips]" value="'+setting.tips+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][style]" value="'+setting.style+'"/> ' +
                    '<textarea name="extend_config['+fieldname+'][setting][option]" style="display:none;">'+setting.option+
                    '</textarea> </div> </div>';
                $('.extend_list').append(tpl);
            }else if(type == 'checkbox'){
                //复选框
                if(setting.option == ''){
                    alert('选项不能为空！');
                    return false;
                }
                var html = '';
                var op = setting.option.split("\n");
                $.each(op,function(i,rs){
                    var at = rs.split("|");
                    html += '<label><input name="extend['+fieldname+'][]" value="'+at[1]+'" type="checkbox" > '+at[0]+'</label>';
                });
                var tpl = '<div class="form-group"> ' +
                    '<label>'+setting.title+'(<a href="javascript:;;" class="extend_del">删除</a>)</label> <div class="y-bg">'+html+
                    '<input type="hidden" name="extend_config['+fieldname+'][fieldname]" value="'+fieldname+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][type]" value="'+type+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][title]" value="'+setting.title+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][tips]" value="'+setting.tips+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][style]" value="'+setting.style+'"/> ' +
                    '<textarea name="extend_config['+fieldname+'][setting][option]" style="display:none;">'+setting.option+
                    '</textarea> </div> </div>';
                $('.extend_list').append(tpl);
            }
            //清空
            $('input[name="extend_add[fieldname]"]').val('');
            $('select[name="extend_add[type]"]').val('');
            $('input[name="extend_add[setting][title]"]').val('');
            $('input[name="extend_add[setting][tips]"]').val('');
            $('input[name="extend_add[setting][style]"]').val('');
            //删除扩展字段
            $('.extend_list .extend_del').click(function(){
                $(this).parent('th').parent('tr').remove();
            });
        });

        $("#child").click(function(){
            if($(this).attr("checked")){
                $('#fmmb').hide();
                $('#plmb').show();
                $('#lbmb').show();
            }else{
                $('#fmmb').show();
                $('#plmb').hide();
                $('#lbmb').hide();
            }
        });
    });
</script>


<script type="text/javascript">
$(document).ready(function() {
    $('#myform').ajaxForm({
        success:  complete,  // post-submit callback
        dataType: 'json'
    });
});
function complete(data){
    if(data.status==1){
        layer.msg(data.info, {
            icon: 1,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
        }, function(){
            window.location.href = "{$Think.cookie.__forward__}";
            return true;
        });
    }else{
        layer.msg(data.info, {
            icon: 2,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
        });
    }
}

$('.thumb_image a').click(function(){
    swfupload('image_uploadfile','image','{:L(uploadfiles)}',1,1,0,1,'jpeg,jpg,png,gif',300,0,'{$cenpic_auth}',yesdo,nodo);
});

function urlrule(m){
    if(m==1){
        $('#urlrule').show();
    }else{
        $('#urlrule').hide();
    }
}

urlrule({$vo['ishtml']});

</script>
{/block}